Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(gvisor): implement get_stats for gVisor #463

Merged
merged 2 commits into from
Jul 7, 2022

Conversation

loresuso
Copy link
Member

@loresuso loresuso commented Jul 7, 2022

Signed-off-by: Lorenzo Susini susinilorenzo1@gmail.com

What type of PR is this?

Uncomment one (or more) /kind <> lines:

/kind bug

/kind cleanup

/kind design

/kind documentation

/kind failing-test

/kind feature

Any specific area of the project related to this PR?

Uncomment one (or more) /area <> lines:

/area build

/area driver-kmod

/area driver-bpf

/area driver-modern-bpf

/area libscap-engine-bpf

/area libscap-engine-gvisor

/area libscap-engine-kmod

/area libscap-engine-modern-bpf

/area libscap-engine-nodriver

/area libscap-engine-noop

/area libscap-engine-source-plugin

/area libscap-engine-udig

/area libscap

/area libsinsp

/area tests

/area proposals

What this PR does / why we need it:

This PR implements the get_stats vtable function for gVisor, letting Falco be able to retrieve statistics like the number of drops or events.
Statistics are collected in a scap_stats structure like usual. To be precise:

  • n_drops_bug is used to count the number of dropped events due to parsing errors
  • n_drops_buffers is used to count the number of dropped events from gVisor side. This number can be retrieved from the header of each message.
  • n_drops is the total number of dropped events, so it is computed as the sum of the previous two.
  • n_evts counts the number of events that were successfully returned by next

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@poiana
Copy link
Contributor

poiana commented Jul 7, 2022

Hi @loresuso. Thanks for your PR.

I'm waiting for a falcosecurity member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -168,6 +171,8 @@ class engine {
std::string m_root_path;
std::string m_trace_session_path;

scap_stats m_stats;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's one tiny thing that I'm not completely happy with about this stats structure, it's the fact that it is not always updated. the m_drops is only updated if the get_stats() function is called. To make the invariant hold I would suggest the following: only save three fields in the class, that would be the number of drops on gvisor side (perhaps with a descriptive name like m_stat_drops_gvisor so we remember what it its), the number of drops because of parsing errors and the total number of events processed. This way we can fill only the relevant fields in the stats structure when requested and we don't need to maintain an m_drops that isn't updated and a bunch of zeroes for fields that are not relevant for gvisor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would make sense, ie: internally use the real gvisor_stats, but expose to the world the expected scap_stats; i like it.
Aside from this, it LGTM!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed! I am working on it, will ping you soon :)

@LucaGuerra
Copy link
Contributor

This is very useful especially for early adopeters of this functionality! I would add it to release. 🚀 left a minor comment.

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
@loresuso
Copy link
Member Author

loresuso commented Jul 7, 2022

I have also noticed that the way we are dealing with dropped_count from gvisor can't be right: that is the total drops from their side, but for each sandbox. I have an idea about how to solve it!

@FedeDP
Copy link
Contributor

FedeDP commented Jul 7, 2022

Mmmh i think that no impl is better than buggy impl, given the time constraints too :)
Wdyt @LucaGuerra ? Do you have any idea to solve this issue?

Signed-off-by: Lorenzo Susini <susinilorenzo1@gmail.com>
@FedeDP
Copy link
Contributor

FedeDP commented Jul 7, 2022

Uh sorry @loresuso misread your previous sentence as "i have no idea about how to solve" :D

@loresuso
Copy link
Member Author

loresuso commented Jul 7, 2022

No problem Fede! Idea is to keep a last_dropped_count for each sandbox. Assuming that this number is always increasing, we can compute the difference between a previously saved value with the current drop count and sum it to the global drop count. I think this works well!

@FedeDP
Copy link
Contributor

FedeDP commented Jul 7, 2022

This makes sense, thanks!
/ok-to-test
🙏

Copy link
Contributor

@LucaGuerra LucaGuerra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really like this solution! LGTM! 🚀

@poiana
Copy link
Contributor

poiana commented Jul 7, 2022

@LucaGuerra: changing LGTM is restricted to collaborators

In response to this:

I really like this solution! LGTM! 🚀

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Contributor

@FedeDP FedeDP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana
Copy link
Contributor

poiana commented Jul 7, 2022

LGTM label has been added.

Git tree hash: 3ca6093f6fb2d930cd678d0b89d8159278c211a0

@poiana poiana added the approved label Jul 7, 2022
Copy link
Member

@Andreagit97 Andreagit97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@poiana poiana merged commit 0f25968 into falcosecurity:master Jul 7, 2022
@poiana
Copy link
Contributor

poiana commented Jul 7, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Andreagit97, FedeDP, loresuso

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants